<?php


namespace Access\Model;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;
use Zend\Db\TableGateway\TableGateway;

class AccessTable
{
    protected $tableGateway;
    protected $adapter;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
        $this->adapter = $tableGateway->getAdapter();
    }

    /**
     * 获取所有存取流水
     * @return array
     */
    public function fetchAll()
    {
        $resultSet = $this->tableGateway->select();
        return $resultSet->toArray();
    }

    /**
     * 获取所有取款流水
     * @return array
     */
    public function getWithdraw()
    {
        $resultSet = $this->tableGateway->select('account < 0');
        return $resultSet->toArray();
    }

    /**
     * 获取所有存款流水
     * @return array
     */
    public function getDeposit()
    {
        $resultSet = $this->tableGateway->select('account > 0');
        return $resultSet->toArray();
    }

    /**
     * 获取某账户的所有存取流水
     * @param $account_id
     * @return array
     */
    public function getAccessByAccountId($account_id)
    {
        $resultSet = $this->tableGateway->select(array('account_id' => $account_id));
        return $resultSet->toArray();
    }

    /**
     * 获取某账户的所有取款流水
     * @param $account_id
     * @return array
     */
    public function getWithdrawByAccountId($account_id)
    {
        $resultSet = $this->tableGateway->select('account < 0 and account_id = ' . $account_id);
        return $resultSet->toArray();
    }

    /**
     * 获取某账户的所有存款流水
     * @param $account_id
     * @return array
     */
    public function getDepositByAccountId($account_id)
    {
        $resultSet = $this->tableGateway->select('account > 0 and account_id = ' . $account_id);
        return $resultSet->toArray();
    }
}